package com.rjgc.title.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rjgc.title.mapper.SkillLevelMapper;
import com.rjgc.title.model.entity.user.SkillLevel;
import com.rjgc.title.service.SkillLevelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 技能等级 服务实现类
 * </p>
 *
 * @author 卓抱抱
 * @since 2022-04-25
 */
@Service
public class SkillLevelServiceImpl extends ServiceImpl<SkillLevelMapper, SkillLevel> implements SkillLevelService {

    @Autowired
    private SkillLevelMapper skillLevelMapper;

    @Override
    public SkillLevel getByUserId(String userId) {

        QueryWrapper<SkillLevel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", userId);
        SkillLevel skillLevel = skillLevelMapper.selectOne(queryWrapper);
        return skillLevel;
    }

    /**
     * 保存并更新
     * @param skillLevel
     */
    @Override
    public void saveSkillLevel(SkillLevel skillLevel) {
        Long id = skillLevel.getId();

        // 判断是否存在id
        if (id != null) {
            // 更新操作
            skillLevelMapper.updateById(skillLevel);
        } else {
            // 添加操作
            skillLevelMapper.insert(skillLevel);
        }
    }
}
